package com.xc.h05.controller.lishenao;

import com.xc.h05.entity.Fm;
import com.xc.h05.service.lishenao.FmService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class FmController {
    @Autowired
    private FmService fmService;

    @GetMapping("/fm")
    public R findAll(Integer pageNum, Integer pageSize,Fm fm){
        return R.ok(fmService.findAllByFm(pageNum,pageSize,fm));
    }

    @PostMapping("/addfm")
    public R add(@RequestBody Fm fm){
        int i = fmService.add(fm);
        if (i>0){
            return R.ok("添加成功");
        }else {
            return R.error();
        }
    }

    @PutMapping("/updatefm")
    public R update(@RequestBody Fm fm){
        int i = fmService.update(fm);
        if (i>0){
            return R.ok("修改成功");
        }else {
            return R.error();
        }
    }
    @DeleteMapping("/deletefm")
    public R delete(Long id){
        int i = fmService.delete(id);
        if (i>0){
            return R.ok("删除成功");
        }else {
            return R.error();
        }
    }
}
